package com.hao.wms.mvc;

import com.hao.wms.domain.Brand;
import com.hao.wms.query.BrandQueryObject;
import com.hao.wms.service.IBrandService;
import com.hao.wms.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class BrandAction extends BaseAction{
	/**
	 * 
	 */
	private IBrandService brandService;
	
	
	private Brand brand = new Brand();
	
	public Brand getBrand() {
		return brand;
	}
	public void setBrand(Brand brand) {
		this.brand = brand;
	}
	private BrandQueryObject queryObject = new BrandQueryObject();
	
	
	public BrandQueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(BrandQueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void setBrandService(IBrandService brandService) {
		this.brandService = brandService;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="品牌列表")
	public String execute() {
		putContext(PAGERESULT, brandService.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改品牌")
	public String input() {
		if(brand.getId()!=null) {
			brand = brandService.get(brand.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改品牌")
	public String saveOrUpdate() {
		try {
			if(brand.getId()!=null) {
                brandService.update(brand);
                addActionMessage("修改成功");
            }else {
                brandService.save(brand);
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSave(){
		if(brand.getId()!=null) {
			brand = brandService.get(brand.getId());
			
		}
	}
	@RequiredPermission(value="删除品牌")
	public String delete() throws IOException {
		brandService.delete(brand);
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
